package com.jinzhi.common.filter;

import com.jinzhi.common.configconsts.wxconsts.LinkConfiggure;
import com.jinzhi.common.vo.WxPayVo;
import com.jinzhi.common.utils.ApiResult;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.chain.Command;
import org.apache.commons.chain.Context;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

/**
 * 保存下单记录
 */
@Slf4j
@Component
public class WxBusinessFilter implements Command {

	private static BigDecimal bigDecimal;

	static {
		bigDecimal = new BigDecimal(100);
	}

	@Override
	public boolean execute(Context context) throws Exception {

		log.info("链路:微信支付执行到:保存下单记录");

		//获取支付对象
		WxPayVo wxPayVo = (WxPayVo) context.get(LinkConfiggure.WX_PAY_VO);

		//获取返回对象
		ApiResult apiResult = (ApiResult) context.get(LinkConfiggure.API_RESULT);

		try {
			//todo 如果统一下单成功，这里通过支付对象对订单信息进行数据保存

		}catch (Exception e){
			apiResult.setCode(LinkConfiggure.WX_ERROR_CODE);
			apiResult.setMsg("微信下单失败");
			return true;
		}

		return false;
	}
}
